package com.java.day05;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;

public class Demo02 {
    public static void main(String[] args) throws IOException {
        //扫描器读取网页的内容

        // 创建url对象
        URL url = new URL("https://www.jiuxian.com/");

        // 创建连接对象
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        // 设置 http 请求的方式  get，post
        conn.setRequestMethod("GET");

        // 获取 响应状态码
        int responseCode = conn.getResponseCode();
        System.out.println(responseCode);

        // 把连接对象中的InputStream对象获取到
        InputStream inputStream = conn.getInputStream();
        Scanner scanner = new Scanner(inputStream);

        while (scanner.hasNextLine()) {
            System.out.println(scanner.nextLine());
        }
    }
}
